// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Contribution.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Forge
{
    #region Using Directives

    using System;
    using System.Collections.Generic;

    using Org.OpenTrader.Framework.Forge.Interfaces;

    #endregion

    /// <summary>
    /// The market book contribution.
    /// </summary>
    [Serializable]
    public class Contribution : IContribution
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Contribution"/> class.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <param name="contributor">
        /// The contributor.
        /// </param>
        /// <param name="size">
        /// The size.
        /// </param>
        public Contribution(string id, string contributor, int size)
        {
            this.ID = id;
            this.Contributor = contributor;
            this.Size = size;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets Contributor.
        /// </summary>
        public string Contributor { get; private set; }

        /// <summary>
        /// Gets or sets ID.
        /// </summary>
        public string ID { get; private set; }

        /// <summary>
        /// Gets or sets Size.
        /// </summary>
        public int Size { get; private set; }

        #endregion

        #region Public Methods

        /// <summary>
        /// The to string.
        /// </summary>
        /// <returns>
        /// The to string.
        /// </returns>
        public override string ToString()
        {
            return string.Format("ID={0};Contributor={1};Size={2};", this.ID, this.Contributor, this.Size);
        }

        #endregion

        /// <summary>
        /// The id comparer.
        /// </summary>
        public class IDComparer : IComparer<string>
        {
            #region Implemented Interfaces

            #region IComparer<string>

            /// <summary>
            /// The compare.
            /// </summary>
            /// <param name="y">
            /// The y.
            /// </param>
            /// <param name="x">
            /// The x.
            /// </param>
            /// <returns>
            /// The compare.
            /// </returns>
            public int Compare(string y, string x)
            {
                // Equals !
                if (y.Equals(x))
                {
                    return 0;
                }

                // The greater has the greater size
                var t = x.GetHashCode() - y.GetHashCode();
                return t;
            }

            #endregion

            #endregion
        }

        /// <summary>
        /// The size comparer.
        /// </summary>
        public class SizeComparer : IComparer<IContribution>
        {
            #region Implemented Interfaces

            #region IComparer<IContribution>

            /// <summary>
            /// The compare.
            /// </summary>
            /// <param name="y">
            /// The y.
            /// </param>
            /// <param name="x">
            /// The x.
            /// </param>
            /// <returns>
            /// The compare.
            /// </returns>
            public int Compare(IContribution y, IContribution x)
            {
                // Equals !
                if (y.ID.Equals(x.ID))
                {
                    return 0;
                }

                // The greater has the greater size
                var t = x.Size - y.Size;
                return t;
            }

            #endregion

            #endregion
        }
    }
}